package com.atguigu.fruit.severlet;

import com.atguigu.fruit.dao.FruitDao;
import com.atguigu.fruit.dao.impl.FruitDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/delete")
public class DelServlet extends HttpServlet {
    FruitDao fruitDao = new FruitDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String fname = new String(req.getParameter("fname").getBytes("iso-8859-1"), "utf-8");
        fruitDao.delFruit(fname);
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=UTF-8") ;
        PrintWriter writer = resp.getWriter();
        writer.println("{\"msg\":\"删除成功\"}");
        writer.flush();
        System.out.println("删除成功");

    }
}
